package org.example.lotterysystem.controller;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.example.lotterysystem.common.domain.Result;
import org.example.lotterysystem.common.domain.dto.CreatePrizeDTO;
import org.example.lotterysystem.common.domain.dto.PageDTO;
import org.example.lotterysystem.common.domain.vo.FindPrizeListVO;
import org.example.lotterysystem.service.PictureService;
import org.example.lotterysystem.service.PrizeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class PrizeController {
    @Resource
    PictureService pictureService;

    @Resource
    PrizeService prizeService;

    /**
     *上传图片
     */
    @RequestMapping("/pic/upload")
    public String uploadPic(MultipartFile file) {
        return pictureService.savePicture(file);
    }

    /**
     * 创建奖品
     */
    @RequestMapping("/prize/create")
    public Result<Long> createPrize(@Valid @RequestPart("param") CreatePrizeDTO createPrizeDTO,
                                    @RequestPart("prizePic") MultipartFile picFile){
        return Result.success(prizeService.createPrize(createPrizeDTO,picFile));
    }

    /**
     * 获取奖品列表
     */
    @RequestMapping("/prize/find-list")
    public Result<FindPrizeListVO> findPrizeList(PageDTO param){
        return Result.success(prizeService.findPrizeList(param));
    }
}
